package com.godyao.service.impl;

import com.godyao.dao.AccountDao;
import com.godyao.framework.beans.factory.annotaions.Autowired;
import com.godyao.framework.beans.factory.annotaions.Qualifier;
import com.godyao.framework.stereotype.Component;
import com.godyao.framework.stereotype.Service;
import com.godyao.framework.transaction.annotation.Transactional;
import com.godyao.pojo.Account;
import com.godyao.service.TransferService;

/**
 * @author godyao
 */
@Service("transferService")
@Transactional(rollbackFor = Exception.class)
public class TransferServiceImpl implements TransferService {
    @Autowired
    @Qualifier("accountDao")
    private AccountDao accountDao;

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        accountDao.updateAccountByCardNo(to);
        int c = 1/0;
        accountDao.updateAccountByCardNo(from);
    }
}
